package com.zhaoyh.websocket;

import javax.websocket.ContainerProvider;
import javax.websocket.DeploymentException;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
import java.io.IOException;
import java.net.URI;

/**
 * @author 祥霸
 * @date 2019/4/15
 */
public class TestClient {

    public static Session session = null;

    static{
        WebSocketContainer container = ContainerProvider.getWebSocketContainer();
        String uri ="ws://127.0.0.1:8080/websocket/demo";
        System.out.println("Connecting to 2"+ uri);
        try {
            session = container.connectToServer(Client.class, URI.create(uri));
        } catch (DeploymentException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        System.out.println("----------------------");

        try {
            TestClient.session.getBasicRemote().sendText("B");
            System.out.println("----------------------");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
